package net.butfly.bus.server.router.impl;

import net.butfly.bus.router.Router;
import net.butfly.bus.server.router.Directory;
import net.butfly.bus.server.router.RoutingPolicy;
import net.butfly.bus.server.router.RoutingPolicyFactory;

public class DefaultRouter implements Router {
	private static Router ins = new DefaultRouter();

	public static Router getInstance() {
		return ins;
	}

	@Override
	public String route(String tx, String version) {
		RoutingPolicy rp = RoutingPolicyFactory.getInstance().getPolicy();
		if (rp != null) {
			String[] nodeAry = Directory.getInstance().lookup(tx, version);
			if (nodeAry != null) {
				return rp.lookup(tx, version, nodeAry);
			}
		}
		return null;
	}

	@Override
	public String route(String tx) {
		// TODO Auto-generated method stub
		return null;
	}
}
